﻿@{
    ViewBag.Title = "分店列表";
    Layout = "~/Views/Shared/_ListLayout.cshtml";
}
@section toolbar{
    <input type="hidden" id="isEmployeeLogin" value="@TEWorkFlow.Web.Client.Common.MyEnv.IsEmployeeLogin.ToString().ToLower()" />
    <table style="width: 100%;">
        <tr>
            <td style="width: 100%;">
                @if(TEWorkFlow.Web.Client.Common.MyEnv.IsEmployeeLogin)
                {
                <a class="mini-button" iconcls="icon-add" onclick="editRow('')" plain="true">增加</a>
                @*<a class="mini-button" iconcls="icon-remove" onclick="remove()" plain="true">删除</a>*@
                <a class="mini-button" iconcls="icon-date-magnify" onclick="showSearchWindow()" plain="true">
                    筛选</a> <span class="separator"></span>
                }
            </td>
            <td style="white-space: nowrap;">
                @if(TEWorkFlow.Web.Client.Common.MyEnv.IsEmployeeLogin)
                {
                <input id="ifexame" class="mini-combobox" textField="text" valueField="id" value="" url="/Category/ExameItems" nullItemText="--是否审核--" emptyText="--是否审核--" onvaluechanged="search()" />
                }
                <input id="AreaCode" name="AreaCode" class="mini-combobox"  textField="text" valueField="id" emptyText="请选择地区..." url="/Category/PaAreas"  allowInput="false" showNullItem="true" nullItemText="请选择地区..."/>
                <input id="bName" class="mini-textbox" emptytext="请输入名称" style="width: 150px;" onenter="onKeyEnter" />
                <a class="mini-button" onclick="search()">查询</a>
            </td>
        </tr>
    </table>
}
@section script
{
    <script type="text/javascript">
        mini.parse();
        function showSearchWindow() {
            var win = mini.get("searchWindow");
            win.show();
        }
        function advSearch() {
            var frm = new mini.Form("frmAdv");
            grid.load(frm.getData(true));
            var win = mini.get("searchWindow");
            win.hide();
        }
        function search() {
            var ifexamine = "";
            var key = "";
            var areaCode = "";
            if (mini.get("#ifexame") != undefined) {
                ifexamine = mini.get("#ifexame").value;
            }
            if (mini.get("#bName") != undefined) {
                key = mini.get("#bName").value;
            }
            if (mini.get("#AreaCode") != undefined) {
                areaCode = mini.get("#AreaCode").getValue();
            }
            grid.load({
                "key": mini.get("#bName").value,
                "IfExamine": ifexamine,
                "AreaCode":areaCode
            });
        }
        function editRow(id) {
            mini.open({
                url: "/Archives/BranchEdit/" + id,
                title: "分店管理",
                iconCls: "icon-user",
                allowResize: false,
                width: 630,
                height: 330,
                onload: function () {
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function viewRow(id) {
            mini.open({
                url: "/Archives/BranchView/" + id,
                title: "分店管理",
                iconCls: "icon-user",
                allowResize: false,
                width: 630,
                height: 330,
                onload: function () {
                },
                ondestroy: function (action) {

                    grid.reload();
                }
            });
        }
        function deleteItem(id) {
            $.ajax({
                url: "/Archives/BranchDelete",
                data: { ids: id },
                dataType: "json",
                success: function (j) {
                    if (j == false) {
                        if (confirm("将要删除的分店存在采购数据，删除后将影响整个系统运行，是否确认删除？") == true) {
                            $.ajax({
                                url: "/Archives/BranchDelete",
                                data: { ids: id, confirm: "true" },
                                dataType: "json",
                                success: function (r) {
                                    grid.reload();
                                }
                            });
                        }
                    }
                    else {
                        grid.reload();
                    }
                },
                error: function () {
                }
            });
        }
        function onBranchActionRenderer(e) {
            var grid = e.sender;
            var record = e.record;
            var uid = record.Id;
            var rowIndex = e.rowIndex;
            var s = "";
            var isEmployeeLogin = $("#isEmployeeLogin").val();
            if (isEmployeeLogin == "true") {
                s = ' <a class="Edit_Button" href="javascript:editRow(\'' + uid + '\')" >编辑</a>';
                    //+ ' <a class="Delete_Button" href="javascript:if(confirm(\'确定要删除这条记录吗？\')){deleteItem(\'' + uid + '\')}">删除</a>';
            } else {
                //s = ' <a class="Edit_Button" href="javascript:viewRow(\'' + uid + '\')" >查看</a>'
            }

            return s;
        }
        function exame(obj, itemid, old) {
            $.ajax({
                url: "/Archives/BranchExame/" + itemid,
                success: function (j) {
                    if (j == true) {
                        $(obj).css("color", "green").text("是");
                    }
                    else {
                        $(obj).css("color", "red").text("否");
                    }
                    $(obj).removeProp("onclick");
                    $(obj).unbind("click").click(function () {
                        exame(obj, itemid, !old)
                    })
                },
                error: function () {
                    alert("失败")
                }
            });
        }
    </script>
}
<div id="datagrid1" class="mini-datagrid" url="/Archives/SearchBranchArchiveList"
    style="width: 100%; height: 100%;" idfield="id" allowresize="false" sizelist="[20,30,50,100]"
    pagesize="20" multiselect="true">
    <div property="columns">
        <div type="indexcolumn" width="30">
        </div>
        <div type="checkcolumn" width="30">
        </div>
        <div field="bName" headeralign="center" align="center" width="60">
            分店名称</div>
        <div field="PyCode" headeralign="center" align="center" width="60">
            拼音码</div>
        <div field="Id" headeralign="center" align="center" width="60">
            分店码</div>
        <div field="AreaName" headeralign="center" align="center" width="60">
            所属区域</div>
        <div field="Functionary" headeralign="center" align="center" width="60">
            负责人</div>
        <div field="FunctionaryPhone" headeralign="center" align="center" width="60">
            负责人电话</div>
        <div field="OfficePhone" headeralign="center" align="center" width="60">
            办公电话</div>
        <div field="ContactAddress" headeralign="center" align="center" width="60">
            联系地址</div>
        @if(TEWorkFlow.Web.Client.Common.MyEnv.IsEmployeeLogin)
        {
        <div field="IfExamine" headeralign="center" align="center" width="30" renderer="onExamRender">
            审核</div>
        <div name="action" width="30" headeralign="center" align="center" renderer="onBranchActionRenderer"
            cellstyle="padding:0;">
            管理</div>
        }
        
    </div>
</div>
